/*
 * port.c
 *
 *  Created on: Nov 2, 2013
 */
#include "MPR121.h"

#include "port.h"

void PORT_vPinMuxInit(void)
{	
	/* Enable the RGB LED pins for GPIO */
	//PORT__nRedLED_PCR 	= PORT_PCR_MUX(1) | PORT_PCR_DSE_MASK;	
	//PORT__nGreenLED_PCR	= PORT_PCR_MUX(1) | PORT_PCR_DSE_MASK;
	//PORT__nBlueLED_PCR 	= PORT_PCR_MUX(1) | PORT_PCR_DSE_MASK;
	
	/*Enable the RGB LED pins for PWM m*/
	PORT__nRedLED_PCR    = PORT_PCR_MUX(2) | PORT_PCR_DSE_MASK; 
	PORT__nGreenLED_PCR   = PORT_PCR_MUX(2) | PORT_PCR_DSE_MASK;
	PORT__nBlueLED_PCR   = PORT_PCR_MUX(2) | PORT_PCR_DSE_MASK;
	
	/* Enable the pins for the selected UART */
	/* Enable the UART0_TXD */
	PORT__nUART_TXD_PCR	= PORT_PCR_MUX(0x2);
	/* Enable the UART0_RXD */
	PORT__nUART_RXD_PCR	= PORT_PCR_MUX(0x2);
	
	/*Enable IRQ pin PTA11, enable pull up resistor */	
	PORT__nIRQpin_PCR = PORT_PCR_MUX(1) 
	                    | PORT_PCR_IRQC(10) 
	                    | PORT_PCR_PE_MASK 
	                    | PORT_PCR_PS_MASK;	
	      
}

void PORT_vDataDirectionInit(void)
{
	//PORT__nRedLED_DDR 	|= RGB_Red_shift;
	//PORT__nGreenLED_DDR |= RGB_Green_shift;
	//PORT__nBlueLED_DDR 	|= RGB_Blue_shift;
	
	PORT__nIRQpin_DDR &= ~PORT__IRQpin_shift;
}

void PORT_vOutputInit(void)
{
	//RGB_Red_OFF;
	//RGB_Green_OFF;
	//RGB_Blue_OFF;	
}

#if (USE_IRQ_PORTA == True)
void PORTA_IRQHandler(void)
{   
/***************************************************************************
* FUNCTION LOCAL DEFINITIONS
****************************************************************************/
#if (USE_IRQ_PTA0 == True)
   uint8 u8tempA0 = 0;
#endif
   
#if (USE_IRQ_PTA1 == True)
   uint8 u8tempA1 = 0;
#endif
   
#if (USE_IRQ_PTA7 == True)
   uint8 u8tempA7 = 0;
#endif
   
#if (USE_IRQ_PTA10 == True)
   uint8 u8temp10 = 0;
#endif
   
#if (USE_IRQ_PTA11 == True)
   uint8 u8tempA11 = 0;
#endif

#if (USE_IRQ_PTA12 == True)
   uint8 u8tempA12 = 0;
#endif

/***************************************************************************
* FUNCTION CODE
****************************************************************************/      

#if (USE_IRQ_PTA0 == True)
   u8tempA0 = PORT__nflagPTA0;

   if (0x01 == u8tempA0)
   {
      /*Clear flag */
      PORT__nClearflagPTA0;
      /*Execute IRQ specific function*/
      PORT__vIRQPTA0();
   }   
#endif
   
#if (USE_IRQ_PTA1 == True)
   u8tempA1 = PORT__nflagPTA1;

   if (0x01 == u8tempA1)
   {
      /*Clear flag */
      PORT__nClearflagPTA1;
      /*Execute IRQ specific function*/
      PORT__vIRQPTA1();
   }   
#endif
   
#if (USE_IRQ_PTA7 == True)
   u8tempA7 = PORT__nflagPTA7;

   if (0x01 == u8tempA7)
   {
      /*Clear flag */
      PORT__nClearflagPTA7;
      /*Execute IRQ specific function*/
      PORT__vIRQPTA7();
   }   
#endif
   
#if (USE_IRQ_PTA10 == True)
   u8tempA10 = PORT__nflagPTA10;

   if (0x01 == u8tempA10)
   {
      /*Clear flag */
      PORT__nClearflagPTA10;
      /*Execute IRQ specific function*/
      PORT__vIRQPTA10();
   }   
#endif
   
#if (USE_IRQ_PTA11 == True)
   u8tempA11 = PORT__nflagPTA11;

   if (0x01 == u8tempA11)
   {
      /*Clear flag */
      PORT__nClearflagPTA11;
      /*Execute IRQ specific function*/
      PORT__vIRQPTA11();
   }   
#endif

#if (USE_IRQ_PTA12 == True)
   u8tempA12 = PORT__nflagPTA12;

   if (0x01 == u8tempA12)
   {
      /*Clear flag */
      PORT__nClearflagPTA12;
      /*Execute IRQ specific function*/
      PORT__vIRQPTA12();
   }   
#endif

   
}
#endif 


#if (USE_IRQ_PORTB == True)
void PORTB_IRQHandler(void)
{
   
}
#endif 


